#!/usr/bin/env bash
# 将执行目录移动到 当前文件所在目录
cd `dirname $0`

version=2.18.0

# 下载安装包
wget -O git-${version}.tar.gz https://github.com/git/git/archive/v${version}.tar.gz
tar xf git-${version}.tar.gz

# 安装依赖包
yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum install -y gcc perl-ExtUtils-MakeMaker

# 卸载旧的git版本（如果之前有安装rpm包）
yum remove -y git

# 安装
(
    cd git-${version}
    make prefix=/usr/local/git all
    make prefix=/usr/local/git install
)

if [[ ! $PATH =~ "/usr/local/git/bin" ]]
then
    echo "export PATH=\$PATH:/usr/local/git/bin" >> /etc/bashrc
    source /etc/bashrc
fi

rm -rf git-${version}.tar.gz git-${version}

cd -
